<template>
  <div class="house-type-floor-plan-display">
    <div v-if="floorPlanUrls.length > 0" class="floor-plan-list">
      <div 
        v-for="(url, index) in floorPlanUrls" 
        :key="index"
        class="floor-plan-item"
        @click="handlePreview(url)"
      >
        <img :src="url" :alt="`户型图${index + 1}`" class="floor-plan-image" />
        <div class="floor-plan-overlay">
          <el-icon><View /></el-icon>
          <span>查看</span>
        </div>
      </div>
    </div>
    <div v-else class="no-floor-plan">
      <el-icon><Picture /></el-icon>
      <span>暂无户型图</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { ElMessage } from 'element-plus'
import { View, Picture } from '@element-plus/icons-vue'

interface Props {
  floorPlanUrl?: string
}

const props = defineProps<Props>()

// 解析户型图URL
const floorPlanUrls = computed(() => {
  if (!props.floorPlanUrl) {
    return []
  }
  
  try {
    const urls = JSON.parse(props.floorPlanUrl)
    if (Array.isArray(urls)) {
      return urls.slice(0, 3) // 最多显示3张
    }
  } catch (error) {
    // 如果不是JSON格式，可能是单个URL
    if (props.floorPlanUrl) {
      return [props.floorPlanUrl]
    }
  }
  
  return []
})

// 预览户型图
const handlePreview = (url: string) => {
  // 在新窗口打开户型图
  window.open(url, '_blank')
}
</script>

<style scoped>
.house-type-floor-plan-display {
  display: flex;
  align-items: center;
}

.floor-plan-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.floor-plan-item {
  position: relative;
  width: 60px;
  height: 40px;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid #e4e7ed;
  transition: all 0.3s;
}

.floor-plan-item:hover {
  border-color: #409eff;
  transform: scale(1.05);
}

.floor-plan-item:hover .floor-plan-overlay {
  opacity: 1;
}

.floor-plan-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.floor-plan-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.3s;
}

.floor-plan-overlay .el-icon {
  font-size: 12px;
  margin-bottom: 2px;
}

.no-floor-plan {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #909399;
  font-size: 12px;
}

.no-floor-plan .el-icon {
  font-size: 14px;
}
</style>
